﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKEA.CMS.Core.Utility;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.BLL;
using System.Transactions;
using System.Collections;
using System.Text;
using HKEA.CMS.Core.BLL.Tbl;
using HKEA.CMS.Core.BLL.Mtbl;
namespace WebApplication
{
    public partial class BranchOffice : BasePage
    {
        #region
        static tblContactInfo staticContactInfo;
        static tblAddress staticAddress;
        static tblCust_Branch staticCustBranch;
        static string vidovalue = string.Empty;
        static string MedioRelated = string.Empty;
        #endregion

        protected int customeruid = 0;
        protected int branchofficeuid = 0;
        protected string type = "";
        tblCust_Branch cust_branchENT = new tblCust_Branch();
        tblCust_BranchBLL cust_branchBLL = new tblCust_BranchBLL();

        tblContactInfo infoENT = new tblContactInfo();
        tblContactInfoBLL infoBLL = new tblContactInfoBLL();
        tblAddress addressENT = new tblAddress();
        tblAddressBLL addressBLL = new tblAddressBLL();
        int telNum = 5;
        int faxNum = 5; 
        int emailNum = 5;
        int webNum = 2;
        int addressUID = 0;
        int infoUID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString[Constant.UrlParamName.CustomerUID] != null)
                {
                    if (int.TryParse(Request.QueryString[Constant.UrlParamName.CustomerUID], out customeruid))
                    {
                        InitPage();
                        WriteStaticEnt();
                    }
                    else
                    {
                        SetNoOption();
                        lblMeg.Text = ResourceManage.GetResourceString("msg200001");
                    }
                }
                else
                {
                    SetNoOption();
                    lblMeg.Text = ResourceManage.GetResourceString("msg200002");
                }
            }
        }
        #region 页面加载方法
        //页面第一次加载执行方法
        protected void InitPage()
        {
            tblCustomer customerENT = new tblCustomer();
            tblCustomerBLL customerBLL = new tblCustomerBLL();
            customerENT.CustomerUID = customeruid;
            customerENT = customerBLL.GetEntity(customerENT);
            if (customerENT != null)
            {
                type = Request.QueryString["type"];
                hidCustomerUID.Value = customeruid.ToString();
                BindBranchList();
                BindBranchImg();
                BindArea();
                AddToDropList();
                if (Request.QueryString[Constant.UrlParamName.BranchOfficeUID] != null)
                {
                    lkQuit.NavigateUrl = lkAdd.NavigateUrl = "BranchOffice.aspx?" + Constant.UrlParamName.CustomerUID + "=" + customeruid + "&type=add";
                    if (int.TryParse(Request.QueryString[Constant.UrlParamName.BranchOfficeUID], out branchofficeuid))
                    {
                        cust_branchENT.CustomerUID = customeruid;
                        cust_branchENT.CustBranchUID = branchofficeuid;
                        cust_branchENT.Deleted = 0;
                        cust_branchENT = cust_branchBLL.GetEntity(cust_branchENT);
                        if (cust_branchENT != null)
                        {
                            //文本赋值
                            hidBranchOfficeUID.Value = branchofficeuid.ToString();
                            SetBranchInfo(cust_branchENT);
                            BingImgRelated();
                            
                            if(cust_branchENT.AddressUID !=null)
                            {SetAddress(Convert.ToInt32(cust_branchENT.AddressUID));}
                            if (cust_branchENT.ContactInfoUID != null)
                            { SetInfo(Convert.ToInt32(cust_branchENT.ContactInfoUID)); }
                            SetVideoValue();
                        }
                        else
                        {
                            SetNoOption();
                            lblMeg.Text = ResourceManage.GetResourceString("msg200012");
                        }
                    }
                    else
                    {
                        SetNoOption();
                        lblMeg.Text = ResourceManage.GetResourceString("msg200001");
                    }
                }
                else
                {
                    initInfo();
                }
            }
            else
            {
                SetNoOption();
                lblMeg.Text = ResourceManage.GetResourceString("msg200014");
            }
        }
        protected void SetNoOption()
        {
            initInfo();
            hidAllowToOption.Value = "false";
            lkbtnSave.Enabled = false;
        }
        //按钮事件后 Page Is PostBack 需要更新的部分数据
        protected void PageIsPostBack()
        {
            hidAddMediaRelated.Value= hidDeleteMediaRelated.Value = hidRelatedMediastrUID.Value = hidUpdateMediaRelated.Value = hidVideoValue.Value = "";
            //刷新 Cusotmer BranchOffice 列表 && BranchOffice 关联图片列表
            BindBranchList();
            BingImgRelated();
            SetVideoValue();
        }
        #endregion

        #region 给文本框赋值
        protected void SetBranchInfo(tblCust_Branch cust_branchENT)
        {
            cust_branchENT.CustomerUID = Convert.ToInt32(hidCustomerUID.Value);
            cust_branchENT.CustBranchUID = branchofficeuid;
            cust_branchENT.Deleted = 0;
            cust_branchENT = cust_branchBLL.GetEntity(cust_branchENT);
            if (cust_branchENT != null)
            {
                if (cust_branchENT.SequenceNo != null)
                { txtSequenceNo.Text = cust_branchENT.SequenceNo.ToString(); }
                txtBranchName_Chi.Text = cust_branchENT.BranchName_Chi;
                txtBranchName_Eng.Text = cust_branchENT.BranchName_Eng;
                if (cust_branchENT.NOfEmp != null)
                { txtNoOfEmployee.Text = cust_branchENT.NOfEmp.ToString(); }
                ckbIsHQ.Checked = cust_branchENT.IsHQ == 0 ? false : true;
            }
        }
        protected void SetAddress(int addressuid)
        {
            addressENT.AddressUID = addressuid;
            addressENT = addressBLL.GetEntity(addressENT);
            if (addressENT != null)
            {
                txtArea_Chi.Text = addressENT.Area_Chi;
                txtArea_Eng.Text = addressENT.Area_Eng;
                txtCity_Chi.Text = addressENT.City_Chi;
                txtCity_Eng.Text = addressENT.City_Eng;
                if (addressENT.CountryUID != null)
                {
                    if (addressENT.mtblCountry.AreaUID != null)
                    {
                        ddlArea.SelectedValue = addressENT.mtblCountry.AreaUID.ToString();
                    }
                    BindCountry();
                    ddlCountry.SelectedValue = addressENT.CountryUID.ToString();
                }
                txtDistrict_Chi.Text = addressENT.District_Chi;
                txtDistrict_Eng.Text = addressENT.District_Eng;
                txtFlat_Chi.Text = addressENT.Flat_Bldg_Chi;
                txtFlat_Eng.Text = addressENT.Flat_Bldg_Eng;
                txtPostCode.Text = addressENT.PostalCode;
                txtProvince_Chi.Text = addressENT.Province_Chi;
                txtProvince_Eng.Text = addressENT.Province_Eng;
                txtStreet_Chi.Text = addressENT.Street_Rd_Chi;
                txtStreet_Eng.Text = addressENT.Street_Rd_Eng;
            }
        }
        private void SetInfo(int infoUID)
        {
            infoENT.ContactInfoUID = infoUID;
            infoENT = infoBLL.GetEntity(infoENT);
            if (infoENT != null)
            {
                hidInfoUID.Value = infoENT.ContactInfoUID.ToString();
                #region Info
                DropDownListTel1.SelectedValue = infoENT.Tel1_Type.ToString();
                TextBoxTC1.Text = infoENT.Tel1_CountryCode;
                TextBoxTA1.Text = infoENT.Tel1_AreaCode;
                TextBoxT1.Text = infoENT.Tel1;
                CheckBoxTD1.Checked = infoENT.Tel1_IsDNC == 1 ? true : false;
                CheckBoxTS1.Checked = infoENT.Tel1_IsSubscribe == 1 ? true : false;

                if (string.IsNullOrEmpty(infoENT.Tel1_CountryCode) && string.IsNullOrEmpty(infoENT.Tel1_AreaCode) && string.IsNullOrEmpty(infoENT.Tel1))
                {
                    PanelT1.Style.Add("display", "none");
                    telNum--;
                }

                DropDownListTel2.SelectedValue = infoENT.Tel2_Type.ToString();
                TextBoxTC2.Text = infoENT.Tel2_CountryCode;
                TextBoxTA2.Text = infoENT.Tel2_AreaCode;
                TextBoxT2.Text = infoENT.Tel2;
                CheckBoxTD2.Checked = infoENT.Tel2_IsDNC == 1 ? true : false;
                CheckBoxTS2.Checked = infoENT.Tel2_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel2_CountryCode) && string.IsNullOrEmpty(infoENT.Tel2_AreaCode) && string.IsNullOrEmpty(infoENT.Tel2))
                {
                    PanelT2.Style.Add("display", "none");
                    telNum--;
                }



                DropDownListTel3.SelectedValue = infoENT.Tel3_Type.ToString();
                TextBoxTC3.Text = infoENT.Tel3_CountryCode;
                TextBoxTA3.Text = infoENT.Tel3_AreaCode;
                TextBoxT3.Text = infoENT.Tel3;
                CheckBoxTD3.Checked = infoENT.Tel3_IsDNC == 1 ? true : false;
                CheckBoxTS3.Checked = infoENT.Tel3_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel3_CountryCode) && string.IsNullOrEmpty(infoENT.Tel3_AreaCode) && string.IsNullOrEmpty(infoENT.Tel3))
                {
                    PanelT3.Style.Add("display", "none");
                    telNum--;
                }

                DropDownListTel4.SelectedValue = infoENT.Tel4_Type.ToString();
                TextBoxTC4.Text = infoENT.Tel4_CountryCode;
                TextBoxTA4.Text = infoENT.Tel4_AreaCode;
                TextBoxT4.Text = infoENT.Tel4;
                CheckBoxTD4.Checked = infoENT.Tel4_IsDNC == 1 ? true : false;
                CheckBoxTS4.Checked = infoENT.Tel4_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel4_CountryCode) && string.IsNullOrEmpty(infoENT.Tel4_AreaCode) && string.IsNullOrEmpty(infoENT.Tel4))
                {
                    PanelT4.Style.Add("display", "none");
                    telNum--;
                }

                DropDownListTel5.SelectedValue = infoENT.Tel5_Type.ToString();
                TextBoxTC5.Text = infoENT.Tel5_CountryCode;
                TextBoxTA5.Text = infoENT.Tel5_AreaCode;
                TextBoxT5.Text = infoENT.Tel5;
                CheckBoxTD5.Checked = infoENT.Tel5_IsDNC == 1 ? true : false;
                CheckBoxTS5.Checked = infoENT.Tel5_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel5_CountryCode) && string.IsNullOrEmpty(infoENT.Tel5_AreaCode) && string.IsNullOrEmpty(infoENT.Tel5))
                {
                    PanelT5.Style.Add("display", "none");
                    telNum--;
                }
                if (telNum <= 0)
                    PanelT5.Style.Add("display", "true");
                #endregion

                #region Fax
                //Fax
                DropDownListFax1.SelectedValue = infoENT.Fax1_Type.ToString();
                TextBoxFC1.Text = infoENT.Fax1_CountryCode;
                TextBoxFA1.Text = infoENT.Fax1_AreaCode;
                TextBoxF1.Text = infoENT.Fax1;
                CheckBoxFD1.Checked = infoENT.Fax1_IsDNC == 1 ? true : false;
                CheckBoxFS1.Checked = infoENT.Fax1_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax1) && string.IsNullOrEmpty(infoENT.Fax1_AreaCode) && string.IsNullOrEmpty(infoENT.Fax2_CountryCode))
                {
                    PanelF1.Style.Add("display", "none");
                    faxNum--;
                }


                DropDownListFax2.SelectedValue = infoENT.Fax2_Type.ToString();
                TextBoxFC2.Text = infoENT.Fax2_CountryCode;
                TextBoxFA2.Text = infoENT.Fax2_AreaCode;
                TextBoxF2.Text = infoENT.Fax2;
                CheckBoxFD2.Checked = infoENT.Fax2_IsDNC == 1 ? true : false;
                CheckBoxFS2.Checked = infoENT.Fax2_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax2) && string.IsNullOrEmpty(infoENT.Fax2_AreaCode) && string.IsNullOrEmpty(infoENT.Fax2_CountryCode))
                {
                    PanelF2.Style.Add("display", "none");
                    faxNum--;
                }




                DropDownListFax3.SelectedValue = infoENT.Fax3_Type.ToString();
                TextBoxFC3.Text = infoENT.Fax3_CountryCode;
                TextBoxFA3.Text = infoENT.Fax3_AreaCode;
                TextBoxF3.Text = infoENT.Fax3;
                CheckBoxFD3.Checked = infoENT.Fax3_IsDNC == 1 ? true : false;
                CheckBoxFS3.Checked = infoENT.Fax3_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax3) && string.IsNullOrEmpty(infoENT.Fax3_AreaCode) && string.IsNullOrEmpty(infoENT.Fax3_CountryCode))
                {
                    PanelF3.Style.Add("display", "none");
                    faxNum--;
                }


                DropDownListFax4.SelectedValue = infoENT.Fax4_Type.ToString();
                TextBoxFC4.Text = infoENT.Fax4_CountryCode;
                TextBoxFA4.Text = infoENT.Fax4_AreaCode;
                TextBoxF4.Text = infoENT.Fax4;
                CheckBoxFD4.Checked = infoENT.Fax4_IsDNC == 1 ? true : false;
                CheckBoxFS4.Checked = infoENT.Fax4_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax4) && string.IsNullOrEmpty(infoENT.Fax4_AreaCode) && string.IsNullOrEmpty(infoENT.Fax4_CountryCode))
                {
                    PanelF4.Style.Add("display", "none");
                    faxNum--;
                }


                DropDownListFax5.SelectedValue = infoENT.Fax5_Type.ToString();
                TextBoxFC5.Text = infoENT.Fax5_CountryCode;
                TextBoxFA5.Text = infoENT.Fax5_AreaCode;
                TextBoxF5.Text = infoENT.Fax5;
                CheckBoxFD5.Checked = infoENT.Fax5_IsDNC == 1 ? true : false;
                CheckBoxFS5.Checked = infoENT.Fax5_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax5) && string.IsNullOrEmpty(infoENT.Fax5_AreaCode) && string.IsNullOrEmpty(infoENT.Fax5_CountryCode))
                {
                    PanelF5.Style.Add("display", "none");
                    faxNum--;
                }
                if (faxNum <= 0)
                    PanelF1.Style.Add("display", "true");
                #endregion
                #region Email
                //email 
                DropDownListEm1.SelectedValue = infoENT.Email1_Type.ToString();
                TextBoxEmail1.Text = infoENT.Email1;
                CheckBoxES1.Checked = infoENT.Email1_IsSubscribe == 1 ? true : false;
                CheckBoxHB1.Checked = infoENT.Email1_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email1))
                {
                    PanelE5.Style.Add("display", "none");
                    emailNum--;
                }



                DropDownListEm2.SelectedValue = infoENT.Email2_Type.ToString();
                TextBoxEmail2.Text = infoENT.Email2;
                CheckBoxES2.Checked = infoENT.Email2_IsSubscribe == 1 ? true : false;
                CheckBoxHB2.Checked = infoENT.Email2_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email2))
                {
                    PanelE2.Style.Add("display", "none");
                    emailNum--;
                }

                DropDownListEm3.SelectedValue = infoENT.Email3_Type.ToString();
                TextBoxEmail3.Text = infoENT.Email3;
                CheckBoxES3.Checked = infoENT.Email3_IsSubscribe == 1 ? true : false;
                CheckBoxHB3.Checked = infoENT.Email3_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email3))
                {
                    PanelE3.Style.Add("display", "none");
                    emailNum--;
                }

                DropDownListEm4.SelectedValue = infoENT.Email4_Type.ToString();
                TextBoxEmail4.Text = infoENT.Email4;
                CheckBoxES4.Checked = infoENT.Email4_IsSubscribe == 1 ? true : false;
                CheckBoxHB4.Checked = infoENT.Email4_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email4))
                {
                    PanelE4.Style.Add("display", "none");
                    emailNum--;
                }


                DropDownListEm5.SelectedValue = infoENT.Email5_Type.ToString();
                TextBoxEmail5.Text = infoENT.Email5;
                CheckBoxES5.Checked = infoENT.Email5_IsSubscribe == 1 ? true : false;
                CheckBoxHB5.Checked = infoENT.Email5_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email5))
                {
                    PanelE5.Style.Add("display", "none");
                    emailNum--;
                }
                if (emailNum <= 0)
                    PanelE1.Style.Add("display", "true");
                #endregion
                #region WebSite
                //website
                DropDownListW1.SelectedValue = infoENT.Website1_Type.ToString();
                TextBoxWeb1.Text = infoENT.Website1;
                if (string.IsNullOrEmpty(infoENT.Website2))
                {
                    PanelW1.Style.Add("display", "none");
                    webNum--;
                }
                DropDownListW2.SelectedValue = infoENT.Website2_Type.ToString();
                TextBoxWeb2.Text = infoENT.Website2;
                if (string.IsNullOrEmpty(infoENT.Website2))
                {
                    PanelW2.Style.Add("display", "none");
                    webNum--;
                }
                if (webNum <= 0)
                    PanelW1.Style.Add("display", "true");
                #endregion
            }
            else
            {
                initInfo();
            }
        }
        protected void SetVideoValue()
        {
            tblMediaRoom_Related relatedENT = new tblMediaRoom_Related();
            tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();
            relatedENT.RelatedUID = branchofficeuid;
            relatedENT.Deleted = 0;
            relatedENT.Category = Constant.MediaRoomCategory.branch_video;
            relatedENT = relatedBLL.GetEntity(relatedENT);
            if (relatedENT != null)
            {
                hidVideoValue.Value = relatedENT.MediaRoomUID.ToString();
                lblVideoFileName.Text = relatedENT.tblMediaRoom.FileName;
            }
        }
        #endregion

        #region 绑定事件
        //绑定Customer所有图片列表
        protected void BindBranchImg()
        {
            tblMediaRoom mediaroomENT = new tblMediaRoom();
            tblMediaRoomBLL mediaroomBLL = new tblMediaRoomBLL();
            mediaroomENT.CustomerUID = Convert.ToInt32(hidCustomerUID.Value);
            mediaroomENT.IsPublish = 1;
            mediaroomENT.MediaType = Constant.MediaType.image;
            mediaroomENT.Category = Constant.MediaRoomCategory.branch_image;
            var list = mediaroomBLL.GetListByENT(mediaroomENT);
            rptImgList.DataSource = list;
            rptImgList.DataBind();
        }
        protected void BindArea()
        {
            mtblArea areaENT = new mtblArea();
            areaENT.Deleted = 0;
            mtblAreaBLL areaBLL = new mtblAreaBLL();
            var list = areaBLL.GetListByENT(areaENT);
            ddlArea.DataSource = list;
            ddlArea.DataTextField = "Area_Chi";
            ddlArea.DataValueField = "AreaUID";
            ddlArea.DataBind();
            BindCountry();
        }
        protected void BindCountry()
        {
            mtblCountry countryENT = new mtblCountry();
            mtblCountryBLL countryBLL = new mtblCountryBLL();
            countryENT.Deleted = 0;
            int areaUID = Convert.ToInt32(ddlArea.SelectedValue);
            countryENT.AreaUID = areaUID;
            var list = countryBLL.GetListByENT(countryENT);
            if (list.Count > 0)
            {
                ddlCountry.DataSource = list;
                ddlCountry.DataTextField = "Country_Chi";
                ddlCountry.DataValueField = "CountryUID";
                ddlCountry.DataBind();
            }
        }
        protected void BindBranchList()
        {
            tblCust_Branch cust_branchENT = new tblCust_Branch();
            tblCust_BranchBLL cust_branchBLL = new tblCust_BranchBLL();
            cust_branchENT.CustomerUID = Convert.ToInt32(hidCustomerUID.Value);
            cust_branchENT.Deleted = 0;
            var list = cust_branchBLL.GetListDetailByENT(cust_branchENT);
            rptBranchOfficeList.DataSource = list;
            rptBranchOfficeList.DataBind();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "AverageBrand();", true);
        }
        protected void BingImgRelated()
        {
            tblMediaRoom_Related relatedENT = new tblMediaRoom_Related();
            tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();
            relatedENT.Category = Constant.MediaRoomCategory.branch_image;
            relatedENT.RelatedUID = branchofficeuid;
            relatedENT.Deleted = 0;
            var list = relatedBLL.GetListWithMediaRoomByENT(relatedENT);
            rptRelatedImgList.DataSource = list;
            rptRelatedImgList.DataBind();
            if (list.Count > 0)
            {
                var count = list.Count;
                for (int i = 0; i < count; i++)
                {
                    //记录原始已经关联的MediaRoomUID, 方便Save事件过滤掉 新增关联MediaRoomUID 确未保存到数据库 的记录
                    hidRelatedMediastrUID.Value += list[i].MediaRoomUID.ToString() + ",";
                }
            }
        }

        private void AddToDropList()
        {
            Hashtable tellHas = Constant.InfoType.tellType;
            Hashtable FaxHas = Constant.InfoType.FaxType;
            Hashtable MailHas = Constant.InfoType.EmailType;
            Hashtable WebHas = Constant.InfoType.WebType;
            //telphone
            DropDownListTel1.DataSource = DropDownListTel2.DataSource = DropDownListTel3.DataSource = DropDownListTel4.DataSource = DropDownListTel5.DataSource = tellHas;
            DropDownListTel1.DataTextField = DropDownListTel2.DataTextField = DropDownListTel3.DataTextField = DropDownListTel4.DataTextField = DropDownListTel5.DataTextField = "value";
            DropDownListTel1.DataValueField = DropDownListTel2.DataValueField = DropDownListTel3.DataValueField = DropDownListTel4.DataValueField = DropDownListTel5.DataValueField = "key";
            DropDownListTel1.DataBind();
            DropDownListTel2.DataBind();
            DropDownListTel3.DataBind();
            DropDownListTel4.DataBind();
            DropDownListTel5.DataBind();
            //Fax
            DropDownListFax1.DataSource = DropDownListFax2.DataSource = DropDownListFax3.DataSource = DropDownListFax4.DataSource = DropDownListFax5.DataSource = FaxHas;
            DropDownListFax1.DataTextField = DropDownListFax2.DataTextField = DropDownListFax3.DataTextField = DropDownListFax4.DataTextField = DropDownListFax5.DataTextField = "value";
            DropDownListFax1.DataValueField = DropDownListFax2.DataValueField = DropDownListFax3.DataValueField = DropDownListFax4.DataValueField = DropDownListFax5.DataValueField = "key";
            DropDownListFax1.DataBind();
            DropDownListFax2.DataBind();
            DropDownListFax3.DataBind();
            DropDownListFax4.DataBind();
            DropDownListFax5.DataBind();
            //Mail
            DropDownListEm1.DataSource = DropDownListEm2.DataSource = DropDownListEm3.DataSource = DropDownListEm4.DataSource = DropDownListEm5.DataSource = MailHas;
            DropDownListEm1.DataTextField = DropDownListEm2.DataTextField = DropDownListEm3.DataTextField = DropDownListEm4.DataTextField = DropDownListEm5.DataTextField = "value";
            DropDownListEm1.DataValueField = DropDownListEm2.DataValueField = DropDownListEm3.DataValueField = DropDownListEm4.DataValueField = DropDownListEm5.DataValueField = "key";
            DropDownListEm1.DataBind();
            DropDownListEm2.DataBind();
            DropDownListEm3.DataBind();
            DropDownListEm4.DataBind();
            DropDownListEm5.DataBind();
            //WEBsit
            DropDownListW1.DataSource = DropDownListW2.DataSource = WebHas;
            DropDownListW1.DataTextField = DropDownListW2.DataTextField = "value";
            DropDownListW1.DataValueField = DropDownListW2.DataValueField = "key";
            DropDownListW1.DataBind();
            DropDownListW2.DataBind();
        }
        /// 新添加时 Contact Information 的样子
        private void initInfo()
        {
            //telephone
            PanelT1.Visible = true;
            PanelT2.Style.Add("display", "none");
            PanelT3.Style.Add("display", "none");
            PanelT4.Style.Add("display", "none");
            PanelT5.Style.Add("display", "none");

            //fax
            PanelF1.Visible = true;
            PanelF2.Style.Add("display", "none");
            PanelF3.Style.Add("display", "none");
            PanelF4.Style.Add("display", "none");
            PanelF5.Style.Add("display", "none");

            //email
            PanelE1.Visible = true;
            PanelE2.Style.Add("display", "none");
            PanelE3.Style.Add("display", "none");
            PanelE4.Style.Add("display", "none");
            PanelE5.Style.Add("display", "none");

            //website
            PanelW1.Visible = true;
            PanelW2.Style.Add("display", "none");


        }
        #endregion

        #region 按钮事件
        protected void lkbtnSave_Click(object sender, EventArgs e)
        {
            if (Context.Request.QueryString[Constant.UrlParamName.CustomerUID] != null)
            {
                int.TryParse(hidCustomerUID.Value, out customeruid);
                int.TryParse(hidBranchOfficeUID.Value, out branchofficeuid);
                if (customeruid > 0)
                {
                    bool Ret = false;
                    if (branchofficeuid > 0)
                    {
                        cust_branchENT.CustBranchUID = branchofficeuid;
                        cust_branchENT.CustomerUID = customeruid;
                        cust_branchENT.Deleted = 0;
                        var temp= cust_branchBLL.GetEntity(cust_branchENT);
                        if (temp != null)
                        {
                            Ret = UpdateMethod();
                            WriteToLog(false);
                        }
                        else
                        {
                            Ret= AddMethod();
                            WriteToLog(true);
                        }
                    }
                    else
                    {
                       Ret= AddMethod();
                       WriteToLog(true);
                    }
                    if (Ret)
                    {
                        PageIsPostBack();
                    }
                }
                else
                { lblMeg.Text = ResourceManage.GetResourceString("msg200001"); }
            }
            else
            { lblMeg.Text = ResourceManage.GetResourceString("msg200002"); }
        }
        protected bool UpdateMethod()
        {
            bool Result = true;
            cust_branchENT.CustomerUID = customeruid;
            cust_branchENT.CustBranchUID = branchofficeuid;
            cust_branchENT.Deleted = 0;
            cust_branchENT = cust_branchBLL.GetEntity(cust_branchENT);
            if (cust_branchENT != null)
            {   //取值
                cust_branchENT = GetBranchInfo(cust_branchENT);
                if (cust_branchENT.AddressUID != null)
                {
                    addressENT.AddressUID = Convert.ToInt32(cust_branchENT.AddressUID);
                    addressENT = addressBLL.GetEntity(addressENT);
                    addressENT = GetAddressValue(addressENT);
                }
                if (cust_branchENT.ContactInfoUID != null)
                {
                    infoENT.ContactInfoUID = Convert.ToInt32(cust_branchENT.ContactInfoUID);
                    infoENT = infoBLL.GetEntity(infoENT);
                    infoENT = GetInfoValue(infoENT);
                }
                List<int> NeedToAddMediaRoomUIDList = new List<int>();
                List<string> NeedToUpdateMediaRoomUIDList = new List<string>();
                List<int> NeedToDelMediaRoomUIDList = new List<int>();

                NeedToAddMediaRoomUIDList = GetUIDList(hidAddMediaRelated);
                NeedToDelMediaRoomUIDList = GetUIDList(hidDeleteMediaRelated);
                NeedToUpdateMediaRoomUIDList = GetUpdateUIDList();

                tblMediaRoom_Related relatedENT = new tblMediaRoom_Related();
                tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();
                relatedENT.Category = Constant.MediaRoomCategory.branch_video;
                relatedENT.Deleted = 0;

                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                options.Timeout = new TimeSpan(0, 3, 0);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    if (!string.IsNullOrEmpty(hidVideoValue.Value))
                    {
                        relatedENT.RelatedUID = branchofficeuid;
                        relatedENT.Category = Constant.MediaRoomCategory.branch_video;
                        relatedENT.Deleted = 0;
                        relatedENT = relatedBLL.GetEntity(relatedENT);
                        if (relatedENT != null)
                        {
                            relatedENT.MediaRoomUID = int.Parse(hidVideoValue.Value);
                            relatedBLL.UpdateENT(relatedENT);
                        }
                        else
                        {
                            relatedBLL.InsertENT(relatedENT);
                        }
                    }

                    cust_branchBLL.UpdateENT(cust_branchENT);
                    //MediaRoom相关
                    relatedBLL.DeleteListFalse(NeedToDelMediaRoomUIDList);
                    relatedBLL.InsertList(NeedToAddMediaRoomUIDList, Constant.MediaRoomCategory.branch_image, cust_branchENT.CustBranchUID);
                    relatedBLL.UpdateList(NeedToUpdateMediaRoomUIDList, Constant.MediaRoomCategory.branch_image);

                    int addressUID = addressBLL.UpdateENT(addressENT);
                    int infoUID = infoBLL.UpdateENT(infoENT);

                    try { scope.Complete(); }//提交事务
                    catch (Exception er)
                    {
                        Result = false;
                    }
                }
                if (Result)
                { lblMeg.Text = ResourceManage.GetResourceString("msg200004"); }
                else
                { lblMeg.Text = ResourceManage.GetResourceString("msg200003"); }
            }
            else
            { lblMeg.Text = ResourceManage.GetResourceString("msg200014"); }
            return Result;
        }
        private bool AddMethod()
        {
            tblMediaRoom_Related relatedENT = new tblMediaRoom_Related();
            tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();
            bool Result = true;
            addressENT = GetAddressValue(addressENT);            
            infoENT = GetInfoValue(infoENT);
            cust_branchENT = GetBranchInfo(cust_branchENT);

            List<int> NeedToAddMediaRoomUIDList = new List<int>();
            List<string> NeedToUpdateMediaRoomUIDList = new List<string>();
            List<int> NeedToDelMediaRoomUIDList = new List<int>();

            NeedToAddMediaRoomUIDList = GetUIDList(hidAddMediaRelated);
            NeedToDelMediaRoomUIDList = GetUIDList(hidDeleteMediaRelated);
            NeedToUpdateMediaRoomUIDList = GetUpdateUIDList();

            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = new TimeSpan(0,3,0);            
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,options))
            {
                cust_branchENT = cust_branchBLL.InsertENTReturnENT(cust_branchENT);
                branchofficeuid = cust_branchENT.CustBranchUID;
                if (!string.IsNullOrEmpty(hidVideoValue.Value))
                {
                    relatedENT.Category = Constant.MediaRoomCategory.branch_video;
                    relatedENT.RelatedUID = cust_branchENT.CustBranchUID;
                    relatedENT.Updated_At = DateTime.Now;
                    relatedENT.Created_At = DateTime.Now;
                    relatedBLL.InsertENT(relatedENT);
                }
                //MediaRoom相关
                relatedBLL.DeleteListFalse(NeedToDelMediaRoomUIDList);
                relatedBLL.InsertList(NeedToAddMediaRoomUIDList, Constant.MediaRoomCategory.branch_image, cust_branchENT.CustBranchUID);
                relatedBLL.UpdateList(NeedToUpdateMediaRoomUIDList, Constant.MediaRoomCategory.branch_image);

                int addressUID= addressBLL.InsertENT(addressENT);

                int infoUID = infoBLL.InsertENT(infoENT);
                //修改cust_branchENT 以保存AddressUID、Info关联
                cust_branchENT.ContactInfoUID = infoUID;
                cust_branchENT.AddressUID = addressUID;
                cust_branchBLL.UpdateENT(cust_branchENT);
                try { scope.Complete(); }
                catch (Exception er) {
                    Result = false;
                }
            }
            if (Result)
            {
                lblMeg.Text = ResourceManage.GetResourceString("msg200006"); 
                ScriptManager.RegisterStartupScript(this, this.GetType(), "cleartxt", "ClearText();", true); 
            }
            else
            { lblMeg.Text = ResourceManage.GetResourceString("msg200005"); }
            return Result;
        }

        //Customer上传图片，刷新图片列表触发事件
        protected void btnRefreshImgList_Click(object sender, EventArgs e)
        {
            BindBranchImg();
        }

        protected void btnRefreshBranchList_Click(object sender, EventArgs e)
        {
            BindBranchList();
        }
        #endregion

        # region 获取文本框值
        protected tblCust_Branch GetBranchInfo(tblCust_Branch ent)
        {
            ent.CustomerUID = customeruid;
            ent.BranchName_Chi = txtBranchName_Chi.Text;
            ent.BranchName_Eng = txtBranchName_Eng.Text;
            int nofemp = 0;
            int seq = 0;
            int.TryParse(txtNoOfEmployee.Text, out nofemp);
            ent.IsHQ = ckbIsHQ.Checked==true ? 1 : 0;
            int.TryParse(txtSequenceNo.Text, out seq);
            ent.SequenceNo = seq;
            ent.NOfEmp = nofemp;
            return ent;
        }

        protected tblAddress GetAddressValue(tblAddress addressENT)
        {
            addressENT.Area_Chi = txtArea_Chi.Text;
            addressENT.Area_Eng = txtArea_Eng.Text;
            addressENT.City_Chi = txtCity_Chi.Text;
            addressENT.City_Eng = txtCity_Eng.Text;
            addressENT.CountryUID = Convert.ToInt32(ddlCountry.SelectedValue);
            addressENT.CreationDate = DateTime.Now;
            addressENT.District_Chi = txtDistrict_Chi.Text;
            addressENT.District_Eng = txtDistrict_Eng.Text;
            addressENT.Flat_Bldg_Chi = txtFlat_Chi.Text;
            addressENT.Flat_Bldg_Eng = txtFlat_Eng.Text;
            addressENT.LastModifyBy = Common.GetManageName();
            addressENT.LastModifyDate = DateTime.Now;
            addressENT.PostalCode = txtPostCode.Text;
            addressENT.Province_Chi = txtProvince_Chi.Text;
            addressENT.Province_Eng = txtProvince_Eng.Text;
            addressENT.Street_Rd_Chi = txtStreet_Chi.Text;
            addressENT.Street_Rd_Eng = txtStreet_Eng.Text;

            mtblCountry countryENT = new mtblCountry();
            countryENT = addressENT.mtblCountry;
            StringBuilder strBuilderEng = new StringBuilder();
            strBuilderEng.Append(txtFlat_Eng.Text).Append(txtStreet_Eng.Text).Append(txtArea_Eng.Text).Append(txtDistrict_Eng.Text).Append(txtCity_Eng.Text).Append(txtProvince_Eng.Text);
            StringBuilder strBuilderChi = new StringBuilder();
            if (countryENT != null)
            {
                strBuilderEng.Append(countryENT.Country_Eng);

                if (countryENT.AreaUID > 0)
                {
                    mtblArea areaENT = new mtblArea();
                    areaENT.AreaUID = (int)countryENT.AreaUID;
                    mtblAreaBLL bll = new mtblAreaBLL();
                    areaENT = bll.GetEntity(areaENT);
                    if (areaENT != null)
                    {
                        strBuilderEng.Append(areaENT.Area_Eng);
                        strBuilderChi.Append(areaENT.Area_Chi);
                    }
                }
                strBuilderChi.Append(countryENT.Country_Chi);
            }
            strBuilderChi.Append(txtProvince_Chi.Text).Append(txtCity_Chi.Text).Append(txtDistrict_Chi.Text).Append(txtArea_Chi.Text).Append(txtStreet_Chi.Text).Append(txtFlat_Chi.Text);
            addressENT.FullAdd_Chi = strBuilderChi.ToString();
            addressENT.FullAdd_Eng = strBuilderEng.ToString();
            return addressENT;
        }

        private tblContactInfo GetInfoValue(tblContactInfo infoENT)
        {
            #region Email
            infoENT.Email1 = TextBoxEmail1.Text;
            infoENT.Email1_IsSubscribe = CheckBoxES1.Checked ? 1 : 0;
            infoENT.Email1_Type = Convert.ToInt32(DropDownListEm1.SelectedValue);
            infoENT.Email1_HardBounce = CheckBoxHB1.Checked ? 1 : 0;
            infoENT.Email2 = TextBoxEmail2.Text;
            infoENT.Email2_IsSubscribe = CheckBoxES2.Checked ? 1 : 0;
            infoENT.Email2_Type = Convert.ToInt32(DropDownListEm2.SelectedValue);
            infoENT.Email2_HardBounce = CheckBoxHB2.Checked ? 1 : 0;
            infoENT.Email3 = TextBoxEmail3.Text;
            infoENT.Email3_IsSubscribe = CheckBoxES3.Checked ? 1 : 0;
            infoENT.Email3_Type = Convert.ToInt32(DropDownListEm3.SelectedValue);
            infoENT.Email3_HardBounce = CheckBoxHB3.Checked ? 1 : 0;
            infoENT.Email4 = TextBoxEmail4.Text;
            infoENT.Email4_IsSubscribe = CheckBoxES4.Checked ? 1 : 0;
            infoENT.Email4_Type = Convert.ToInt32(DropDownListEm4.SelectedValue);
            infoENT.Email4_HardBounce = CheckBoxHB4.Checked ? 1 : 0;
            infoENT.Email5 = TextBoxEmail5.Text;
            infoENT.Email5_IsSubscribe = CheckBoxES5.Checked ? 1 : 0;
            infoENT.Email5_Type = Convert.ToInt32(DropDownListEm5.SelectedValue);
            infoENT.Email5_HardBounce = CheckBoxHB5.Checked ? 1 : 0;
            #endregion
            #region Fax
            infoENT.Fax1 = TextBoxF1.Text;
            infoENT.Fax1_AreaCode = TextBoxFA1.Text;
            infoENT.Fax1_CountryCode = TextBoxFC1.Text;
            infoENT.Fax1_IsDNC = CheckBoxFD1.Checked ? 1 : 0;
            infoENT.Fax1_IsSubscribe = CheckBoxFS1.Checked ? 1 : 0;
            infoENT.Fax1_Type = Convert.ToInt32(DropDownListFax1.SelectedValue);

            infoENT.Fax2 = TextBoxF2.Text;
            infoENT.Fax2_AreaCode = TextBoxFA2.Text;
            infoENT.Fax2_CountryCode = TextBoxFC2.Text;
            infoENT.Fax2_IsDNC = CheckBoxFD2.Checked ? 1 : 0;
            infoENT.Fax2_IsSubscribe = CheckBoxFS2.Checked ? 1 : 0;
            infoENT.Fax2_Type = Convert.ToInt32(DropDownListFax2.SelectedValue);

            infoENT.Fax3 = TextBoxF3.Text;
            infoENT.Fax3_AreaCode = TextBoxFA3.Text;
            infoENT.Fax3_CountryCode = TextBoxFC3.Text;
            infoENT.Fax3_IsDNC = CheckBoxFD3.Checked ? 1 : 0;
            infoENT.Fax3_IsSubscribe = CheckBoxFS3.Checked ? 1 : 0;
            infoENT.Fax3_Type = Convert.ToInt32(DropDownListFax3.SelectedValue);

            infoENT.Fax4 = TextBoxF4.Text;
            infoENT.Fax4_AreaCode = TextBoxFA4.Text;
            infoENT.Fax4_CountryCode = TextBoxFC4.Text;
            infoENT.Fax4_IsDNC = CheckBoxFD4.Checked ? 1 : 0;
            infoENT.Fax4_IsSubscribe = CheckBoxFS4.Checked ? 1 : 0;
            infoENT.Fax4_Type = Convert.ToInt32(DropDownListFax4.SelectedValue);

            infoENT.Fax5 = TextBoxF5.Text;
            infoENT.Fax5_AreaCode = TextBoxFA5.Text;
            infoENT.Fax5_CountryCode = TextBoxFC5.Text;
            infoENT.Fax5_IsDNC = CheckBoxFD5.Checked ? 1 : 0;
            infoENT.Fax5_IsSubscribe = CheckBoxFS5.Checked ? 1 : 0;
            infoENT.Fax5_Type = Convert.ToInt32(DropDownListFax5.SelectedValue);
            #endregion
            #region Tel
            infoENT.Tel1 = TextBoxT1.Text;
            infoENT.Tel1_AreaCode = TextBoxTA1.Text;
            infoENT.Tel1_CountryCode = TextBoxTC1.Text;
            infoENT.Tel1_IsDNC = CheckBoxTD1.Checked ? 1 : 0;
            infoENT.Tel1_IsSubscribe = CheckBoxTS1.Checked ? 1 : 0;
            infoENT.Tel1_Type = Convert.ToInt32(DropDownListTel1.SelectedValue);

            infoENT.Tel2 = TextBoxT2.Text;
            infoENT.Tel2_AreaCode = TextBoxTA2.Text;
            infoENT.Tel2_CountryCode = TextBoxTC2.Text;
            infoENT.Tel2_IsDNC = CheckBoxTD2.Checked ? 1 : 0;
            infoENT.Tel2_IsSubscribe = CheckBoxTS2.Checked ? 1 : 0;
            infoENT.Tel2_Type = Convert.ToInt32(DropDownListTel2.SelectedValue);

            infoENT.Tel3 = TextBoxT3.Text;
            infoENT.Tel3_AreaCode = TextBoxTA3.Text;
            infoENT.Tel3_CountryCode = TextBoxTC3.Text;
            infoENT.Tel3_IsDNC = CheckBoxTD3.Checked ? 1 : 0;
            infoENT.Tel3_IsSubscribe = CheckBoxTS3.Checked ? 1 : 0;
            infoENT.Tel3_Type = Convert.ToInt32(DropDownListTel3.SelectedValue);

            infoENT.Tel4 = TextBoxT4.Text;
            infoENT.Tel4_AreaCode = TextBoxTA4.Text;
            infoENT.Tel4_CountryCode = TextBoxTC4.Text;
            infoENT.Tel4_IsDNC = CheckBoxTD4.Checked ? 1 : 0;
            infoENT.Tel4_IsSubscribe = CheckBoxTS4.Checked ? 1 : 0;
            infoENT.Tel4_Type = Convert.ToInt32(DropDownListTel4.SelectedValue);

            infoENT.Tel5 = TextBoxT5.Text;
            infoENT.Tel5_AreaCode = TextBoxTA5.Text;
            infoENT.Tel5_CountryCode = TextBoxTC5.Text;
            infoENT.Tel5_IsDNC = CheckBoxTD5.Checked ? 1 : 0;
            infoENT.Tel5_IsSubscribe = CheckBoxTS5.Checked ? 1 : 0;
            infoENT.Tel5_Type = Convert.ToInt32(DropDownListTel5.SelectedValue);
            #endregion
            #region WebSite
            infoENT.Website1 = TextBoxWeb1.Text;
            infoENT.Website1_Type = Convert.ToInt32(DropDownListW1.SelectedValue);
            infoENT.Website2 = TextBoxWeb2.Text;
            infoENT.Website2_Type = Convert.ToInt32(DropDownListW2.SelectedValue);
            #endregion
            return infoENT;
        }

        /// <summary>
        /// 获取文本框的值并写入静态变量
        /// </summary>
        protected void WriteStaticEnt()
        {
            staticCustBranch = new tblCust_Branch();
            staticContactInfo = new tblContactInfo();
            staticAddress = new tblAddress();
            staticCustBranch = GetBranchInfo(staticCustBranch);
            staticContactInfo = GetInfoValue(staticContactInfo);
            staticAddress = GetAddressValue(staticAddress);
            vidovalue=hidVideoValue.Value;
            MedioRelated = hidAddMediaRelated.Value;
        }


        protected List<int> GetUIDList(HiddenField hidName)
        {
            List<int> UIDList = new List<int>();
            if (!string.IsNullOrEmpty(hidName.Value))
            {
                UIDList = hidName.Value.StringToList();
            }
            return UIDList;
        }

        protected List<string> GetUpdateUIDList()
        {
            List<string> strUIDList = new List<string>();
            if (!string.IsNullOrEmpty(hidUpdateMediaRelated.Value))
            {
                string[] strList = hidUpdateMediaRelated.Value.Split(',');
                strUIDList = strList.ToList();
            }
            return strUIDList;
        }
        #endregion

        protected void ddlArea_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindCountry();
        }

        #region  写入loge的数据
        protected string MediaRelatedChange(string info)
        {
            List<int> oldList = new List<int>();
            List<int> newList = new List<int>();
            string[] Str = MedioRelated.Split(',');
            string[] tempStr = hidAddMediaRelated.Value.Split(',');
            for (int i = 0; i < Str.Length - 1; i++)
            {

                int temp = Str[i].Equals("") ? 0 : Convert.ToInt32(Str[i]);
                if (temp > 0)
                    oldList.Add(temp);
            }
            for (int i = 0; i < tempStr.Length - 1; i++)
            {
                int temp = tempStr[i].Equals("") ? 0 : Convert.ToInt32(tempStr[i]);
                if (temp > 0)
                    newList.Add(temp);
            }
            List<int> temp_a = GetChangeList(oldList, newList);
            List<int> temp_b = GetChangeList(newList, oldList);
            if (temp_a.Count > 0 || temp_b.Count > 0)
            {
                info += "MediaRelated have change";
            }
            return info;
        }
        private string GetVideoValueChange(string info)
        {
            string temp = hidVideoValue.Value;
            if (vidovalue.Trim() != temp.Trim()) {
                info="Video have change";
            }
            return info;
        }
        private List<int> GetChangeList(List<int> Contrast, List<int> Source)
        {
            List<int> add = new List<int>();
            for (int i = 0; i < Contrast.Count(); i++)
            {
                bool has = Source.Contains(Contrast[i]);
                if (has == false)
                    add.Add(Contrast[i]);
            }
            return add;
        }
        
        protected void WriteToLog(bool _bool)
        {
            BasePage basepage = new BasePage();
            string ChangeLoge = string.Empty;
            string LoginName = basepage.GetManageFromSession().User_Name;

            #region 获取最新的数据判断更改了什么
            ChangeLoge += GetAddressChange(ChangeLoge);
            ChangeLoge += MediaRelatedChange(ChangeLoge);
            ChangeLoge += GetVideoValueChange(ChangeLoge);
            ChangeLoge += GetInfoChange(ChangeLoge);
            if (_bool) {
                ChangeLoge = ChangeLoge.Replace("change","add");
            }
            #endregion

            Literal CompanyName = usermeg.FindControl("ltlCompanyName_eng") as Literal;
            tblHistory entlog = new tblHistory();
            entlog.HistoryCatUID = 2;
            entlog.HistoryTypeUID = 6;
            entlog.CustomerUID = Convert.ToInt32(Request.QueryString[Constant.UrlParamName.CustomerUID]);
            entlog.Cust_MemberUID = 0;
            entlog.ContactPersonUID = 0;
            entlog.History_Detail = LoginName + " {" + CompanyName.Text + "}{BranchOffice} " + ChangeLoge;
            entlog.LastModifyBy = LoginName;
            int tal = tblHistoryBLL.GetInstance().InsertENT(entlog);
        }
        protected string GetAddressChange(string ChangeLoge)
        {
            if (Val(staticCustBranch.SequenceNo.ToString()) != txtSequenceNo.Text) { ChangeLoge += ", SequenceNo change to" + txtSequenceNo.Text; }
            if (Val(staticCustBranch.BranchName_Eng) != txtBranchName_Eng.Text) { ChangeLoge += ", BranchName change to" + txtBranchName_Eng.Text; }
            if (Val(staticCustBranch.BranchName_Chi) != txtBranchName_Chi.Text) { ChangeLoge += ", 分行名稱 change to" + txtBranchName_Chi.Text; }
            if (Val(staticCustBranch.NOfEmp.ToString()) != txtNoOfEmployee.Text) { ChangeLoge += ", 	No. of Employee change to" + txtNoOfEmployee.Text; }
            if (Val(staticAddress.Area_Chi) != txtArea_Chi.Text) { ChangeLoge += ", 地區 change to " + txtArea_Chi.Text; }
            if (Val(staticAddress.Area_Eng) != txtArea_Eng.Text) { ChangeLoge += " , Area change to " + txtArea_Eng.Text; }
            if (Val(staticAddress.City_Chi) != txtCity_Chi.Text) { ChangeLoge += " , 城市 change to " + txtCity_Chi.Text; }
            if (Val(staticAddress.City_Eng) != txtCity_Eng.Text) { ChangeLoge += " , City change to " + txtCity_Eng.Text; }
            if (Val(staticAddress.District_Chi) != txtDistrict_Chi.Text) { ChangeLoge += " , 區域 change to " + txtDistrict_Chi.Text; }
            if (Val(staticAddress.District_Eng) != txtDistrict_Eng.Text) { ChangeLoge += " , District change to " + txtDistrict_Eng.Text; }
            if (Val(staticAddress.Flat_Bldg_Eng) != txtFlat_Eng.Text) { ChangeLoge += " , 室, 樓層, 大廈 change to " + txtFlat_Eng.Text; }
            if (Val(staticAddress.Flat_Bldg_Chi) != txtFlat_Chi.Text) { ChangeLoge += " , Flat_Bldg change to " + txtFlat_Chi.Text; }
            if (Val(staticAddress.Province_Chi) != txtProvince_Chi.Text) { ChangeLoge += " , 州, 省 change to " + txtProvince_Chi.Text; }
            if (Val(staticAddress.Province_Eng) != txtProvince_Eng.Text) { ChangeLoge += " , Province change to " + txtProvince_Eng.Text; }
            if (Val(staticAddress.Street_Rd_Chi) != txtStreet_Chi.Text) { ChangeLoge += " , 街道 change to " + txtStreet_Chi.Text; }
            if (Val(staticAddress.Street_Rd_Eng) != txtStreet_Eng.Text) { ChangeLoge += " , Street_Rd change to" + txtStreet_Eng.Text; }
            if (Val(staticAddress.PostalCode) != txtPostCode.Text) { ChangeLoge += " , PostalCode change to " + txtPostCode.Text; }
            if (Val(staticAddress.Department_Eng) != ddlArea.SelectedItem.Text) { ChangeLoge += " , Continent change to " + ddlArea.SelectedItem.Text; }
            if (Val(staticAddress.Department_Chi) != ddlCountry.SelectedItem.Text) { ChangeLoge += " , Country change to" + ddlCountry.SelectedItem.Text; }
            return ChangeLoge;
        }
        protected string GetInfoChange(string str)
        {
            if (staticContactInfo != null)
            {
                tblContactInfo infoENT = new tblContactInfo();
                infoENT = GetInfoValue(infoENT);

                if (Val(staticContactInfo.Tel1) != Val(infoENT.Tel1) | Val(staticContactInfo.Tel2) != Val(infoENT.Tel2) | Val(staticContactInfo.Tel3) != Val(infoENT.Tel3) | Val(staticContactInfo.Tel4) != Val(infoENT.Tel4) | Val(staticContactInfo.Tel5) != Val(infoENT.Tel5))
                {
                    str += "Tel have change; ";
                }
                if (staticContactInfo.Tel1_IsDNC != infoENT.Tel1_IsDNC | staticContactInfo.Tel2_IsDNC != infoENT.Tel2_IsDNC | staticContactInfo.Tel3_IsDNC != infoENT.Tel3_IsDNC | staticContactInfo.Tel4_IsDNC != infoENT.Tel4_IsDNC | staticContactInfo.Tel5_IsDNC != infoENT.Tel5_IsDNC)
                {
                    str += "Tel DNC have change; ";
                }
                if (staticContactInfo.Tel1_IsSubscribe != infoENT.Tel1_IsSubscribe | staticContactInfo.Tel2_IsSubscribe != infoENT.Tel2_IsSubscribe | staticContactInfo.Tel3_IsSubscribe != infoENT.Tel3_IsSubscribe | staticContactInfo.Tel4_IsSubscribe != infoENT.Tel4_IsSubscribe | staticContactInfo.Tel5_IsSubscribe != infoENT.Tel5_IsSubscribe)
                {
                    str += "Tel Subscrib have change; ";
                }
                if (Val(staticContactInfo.Fax1) != Val(infoENT.Fax1) | Val(staticContactInfo.Fax2) != Val(infoENT.Fax2) | Val(staticContactInfo.Fax3) != Val(infoENT.Fax3) | Val(staticContactInfo.Fax4) != Val(infoENT.Fax4) | Val(staticContactInfo.Fax5) != Val(infoENT.Fax5))
                {
                    str += "Fax have change";
                }
                if (staticContactInfo.Fax1_IsDNC != infoENT.Fax1_IsDNC | staticContactInfo.Fax2_IsDNC != infoENT.Fax2_IsDNC | staticContactInfo.Fax3_IsDNC != infoENT.Fax3_IsDNC | staticContactInfo.Fax4_IsDNC != infoENT.Fax4_IsDNC | staticContactInfo.Fax5_IsDNC != infoENT.Fax5_IsDNC)
                {
                    str += "Fax DNC chave change";
                }
                if (staticContactInfo.Fax1_IsSubscribe != infoENT.Fax1_IsSubscribe | staticContactInfo.Fax2_IsSubscribe != infoENT.Fax2_IsSubscribe | staticContactInfo.Fax3_IsSubscribe != infoENT.Fax3_IsSubscribe | staticContactInfo.Fax4_IsSubscribe != infoENT.Fax4_IsSubscribe | staticContactInfo.Fax5_IsSubscribe != infoENT.Fax5_IsSubscribe)
                {
                    str += "Fax Subscribe have change";
                }
                if (Val(staticContactInfo.Email1) != Val(infoENT.Email1) | Val(staticContactInfo.Email2) != Val(infoENT.Email2) | Val(staticContactInfo.Email3) != Val(infoENT.Email3) | Val(staticContactInfo.Email4) != Val(infoENT.Email4) | Val(staticContactInfo.Email5) != Val(infoENT.Email5))
                {
                    str += "Email have change";
                }
                if (staticContactInfo.Email1_IsSubscribe != infoENT.Email1_IsSubscribe | staticContactInfo.Email2_IsSubscribe != infoENT.Email2_IsSubscribe | staticContactInfo.Email3_IsSubscribe != infoENT.Email3_IsSubscribe | staticContactInfo.Email4_IsSubscribe != infoENT.Email4_IsSubscribe | staticContactInfo.Email5_IsSubscribe != infoENT.Email5_IsSubscribe)
                {
                    str += "Email Subscribe have change";
                }
                if (staticContactInfo.Email1_HardBounce != infoENT.Email1_HardBounce | staticContactInfo.Email2_HardBounce != infoENT.Email2_HardBounce | staticContactInfo.Email3_HardBounce != infoENT.Email3_HardBounce | staticContactInfo.Email4_HardBounce != infoENT.Email4_HardBounce | staticContactInfo.Email5_HardBounce != infoENT.Email5_HardBounce)
                {
                    str += "Email Subscribe have change";
                }
                if (staticContactInfo.Website1 != infoENT.Website1 | staticContactInfo.Website2 != infoENT.Website2 | staticContactInfo.Website3 != infoENT.Website3 | staticContactInfo.Website4 != infoENT.Website4 | staticContactInfo.Website5 != infoENT.Website5)
                {
                    str += "Website have change";
                }
                if (staticContactInfo.Website1_Type != infoENT.Website1_Type | staticContactInfo.Website2_Type != infoENT.Website2_Type)
                {
                    str += "Website type have change";
                }
            }
            return str;
        }

        protected string Val(string str)
        {
            if (string.IsNullOrEmpty(str))
                str = "";
            return str;
        }
        #endregion
    }
}